package com.jboost.hyk.common.constant;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.jboost.common.constant.CommonConstant;
import com.jboost.common.constant.EnumInterface;

/**
 *@ClassName
 *@Description 账号状态
 *@Author cxn
 *@Date 2022-10-11
 *@Version
 **/
public enum UserStatusEnum implements EnumInterface {
//  账号状态：new-未开通；open-开通；close-关闭；
    NEW("new", "未开通",0),
    OPEN("open", "已开通",1),
    CLOSE("close", "已关闭",2);

    UserStatusEnum(String code, String desc,Integer val) {
        this.code = code;
        this.desc = desc;
        this.val = val;
    }

    @EnumValue
    @JsonValue    //标记响应json值
    private final String code;
    private final String desc;
    private final Integer val;

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getVal() {
        return val;
    }

    public static UserStatusEnum getByCode(String code) {
        UserStatusEnum[] enums = UserStatusEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if(enums[i].code.equals(code)){
                return enums[i];
            }
        }
        return null;
    }
    public static UserStatusEnum getByVal(Integer val) {
        UserStatusEnum[] enums = UserStatusEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if(enums[i].val == val){
                return enums[i];
            }
        }
        return null;
    }
    public static String getDescByCode(String code) {
        UserStatusEnum status = UserStatusEnum.getByCode(code);
        if(null == status){
            return CommonConstant.UNDIFIND_DEFALUT;
        }
        return status.getDesc();
    }
    public static String getDescByVal(String val) {
        if (null == val){
            return CommonConstant.UNDIFIND_DEFALUT;
        }
        Integer intVal = Integer.parseInt(val);
        UserStatusEnum status = UserStatusEnum.getByVal(intVal);
        if(null == status){
            return CommonConstant.UNDIFIND_DEFALUT;
        }
        return status.getDesc();
    }
    public static Integer getValByCode(String code) {
        UserStatusEnum status = UserStatusEnum.getByCode(code);
        if(null == status){
            return CommonConstant.INT_STATUS_0;
        }
        return status.getVal();
    }

    @Override
    public String desc() {
        return this.desc;
    }

    @Override
    public Integer value() {
        return this.val;
    }

    @Override
    public String code() {
        return this.val.toString();
    }

}
